package com.example.blog.controller;

import com.example.blog.dao.pojo.User;
import com.example.blog.service.UserService;
import com.example.blog.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("users")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping({"currenUser"})
    public Result currenUser(@RequestHeader("Authorization") String token) {
        return this.userService.findUserByToken(token);
    }

    @GetMapping({"avatar/{account}"})
    public Result avatar(@PathVariable("account") String account) {
        return Result.success(this.userService.findUserByAccount(account).getAvatar());
    }

    @PostMapping({"userinfo"})
    public Result userinfo(@RequestHeader("Authorization") String token) {
        return Result.success(this.userService.findUserInfoByToken(token));
    }

    @PostMapping({"changeInfo"})
    public Result updateUserInfo(@RequestBody User user) {
        return this.userService.updateUserInfo(user);
    }

    @PostMapping({"publish"})
    public Result userPublish(@RequestHeader("Authorization") String token) {
        return Result.success(this.userService.findUserPublish(token));
    }
    @PostMapping({"likes"})
    public Result userLikes(@RequestHeader("Authorization") String token) {
        return Result.success(this.userService.findUserLikes(token));
    }
    @PostMapping({"collection"})
    public Result userCollection(@RequestHeader("Authorization") String token) {
        return Result.success(this.userService.findUserCollection(token));
    }
}
